package com.funo.logic.generate.code;


import com.funo.logic.generate.wrapper.AnnotationClassWrapper;
import com.funo.logic.generate.wrapper.ClassWrapper;
import com.funo.logic.util.HumpUnderLineUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 参数代码生成
 * @since 2024年7月23日10:33:05
 * @author cms
 */
public class ParamCodeSupport extends AbstractCodeSupport implements CodeSupport {

    /**
     * 参数类型
     */
    private ClassWrapper type;
    /**
     * 参数名称
     */
    private String name;

    private List<AnnotationClassWrapper> annotationList = new ArrayList<>();

    public static ParamCodeSupport of(ClassWrapper type, String name) {
        ParamCodeSupport paramTarget = new ParamCodeSupport();
        paramTarget.setType(type);
        paramTarget.setName(name);
        return paramTarget;
    }

    public ClassWrapper getType() {
        return type;
    }

    private void setType(ClassWrapper type) {
        this.type = type;
    }

    @Override
    public String getName() {
        return name;
    }

    private void setName(String name) {
        this.name = name;
    }

    @Override
    public String generateCode() {

        for (AnnotationClassWrapper annotation : annotationList) {
            codeBuffer.append(annotation.generateCode());
            addSpace();
        }
        codeBuffer.append(type.getName());
        addSpace();
        codeBuffer.append(HumpUnderLineUtil.lowerCaseLetters(name));

        return codeBuffer.toString();
    }



    public void addAnnotation(AnnotationClassWrapper annotation) {
        annotationList.add(annotation);
    }
}
